package com.backend.system.controller;

import com.backend.system.beans.role.*;
import com.backend.system.common.PageBean;
import com.backend.system.common.ResponseEntity;
import com.backend.system.service.IRoleService;
import com.backend.system.service.manage.RoleManage;
import com.backend.system.util.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author backend-manage
 * @since 2024-04-02
 */
@Api(tags = "角色表 前端控制器")
@RestController
@RequestMapping("/sys/role")
public class RoleController {

    @Resource
    private IRoleService roleService;

    /**
     * 新增或修改角色
     */
    @ApiOperation("新增或修改角色")
    @PostMapping("/addOrUpdate")
    public ResponseEntity<Boolean> addOrUpdate(@Valid @RequestBody RoleAddOrUpdateReq req) {
        return ResponseUtil.success(RoleManage.addOrUpdate(req));
    }

    /**
     * 查询所有角色
     */
    @PostMapping("/listAll")
    @ApiOperation("查询所有角色")
    public ResponseEntity<List<RoleQueryAllVO>> listAll() {
        return ResponseUtil.success(roleService.listAll());
    }


    /**
     * 查询指定用户的所有角色（含已分配，未分配）
     */
    @PostMapping("/listAllByUser")
    @ApiOperation("查询指定用户的所有角色（含已分配，未分配）")
    public ResponseEntity<List<RoleQueryAllByUserVO>> listAllByUser(@Valid @RequestBody RoleQueryAllByUserReq req) {
        return ResponseUtil.success(roleService.listAllByUser(req));
    }

    /**
     * 分页查询所有角色
     */
    @PostMapping("/listByPage")
    @ApiOperation("分页查询所有角色")
    public ResponseEntity<PageBean<RoleQueryVO>> listByPage(@Valid @RequestBody RoleQueryReq req) {
        req.setDefaultPageInfo();
        return ResponseUtil.success(roleService.listByPage(req));
    }
}
